﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class PushMoneyManage_DayEndManage : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("300500100");
        if (!IsPostBack)
        {
            Bind();
            Init_DayEnd();
        }
    }
    #region 初始化未日结列表
    private void Init_DayEnd()
    {
        DDLRQ.DataSource = new BLL.BalanceCyc().GetDayEndList();
        DDLRQ.DataTextField = "JieSuanRi";
        DDLRQ.DataValueField = "JieSuanRi";
        DDLRQ.DataBind();
    }
    #endregion

    #region 已结算列表
    private void Bind()
    {
        int pageCount, rowCount;
        List<Model.BalanceCyc> properties = new BLL.BalanceCyc().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "BC_ADDDate", false, "", out pageCount, out rowCount);
        BalanceCycListControl1.Bind(properties);
        AspNetPager1.RecordCount = rowCount;
    }
    #endregion

    #region 日结
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Check.CheckPermission("300500100", "00030"))
        {
            Model.SYSPARAM sysparam = new Model.SYSPARAM();
            sysparam = new BLL.SYSPARAM().GetModel("007");
            if (sysparam.SP_PARAM15 == "1")  //订单分摊开启
            {
                string result = new BLL.BalanceCyc().DayEnd(DDLRQ.SelectedValue, Share.UserValue(0), sysparam);
                if (result == "")
                {
                    Share.Alert(this.Page, "日结完成");
                    Bind();
                    Init_DayEnd();
                }
                else
                {
                    Share.Alert(this.Page, result);
                }
            }
            else
            {
                Share.Alert(this.Page, "订单现金分成未开启");
            }
        }
        else
        {
            BLL.Common.Alert(this, "无权操作");
        }
    }
    #endregion
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
}
